import request from '@/utils/request.ts'
import type { Tag, TagResponseData } from './type'

enum API {
  // 获取全部标签数据
  TAG_GETALL_URL = '/tag/admin/getall/',
  // 添加标签
  ADD_TAG_URL = '/tag/admin/create/',
  // 查询特定标签
  TAG_URL = '/tag/admin/get/',
  // 修改标签
  UPDATE_TAG_URL = '/tag/admin/update/',
  // 删除标签
  DELETE_TAG_URL = '/tag/admin/delete/',
  // 相似查询
  TAG_SIMILAR_URL = '/tag/admin/similar/',
}

export const reqHasTag = () =>
  request.get<any, TagResponseData>(API.TAG_GETALL_URL)

export const reqAddTag = (data: Tag) => {
  return request.post<any, any>(API.ADD_TAG_URL, data)
}

export const reqUpdateTag = (data: Tag) => {
  return request.put<any, any>(API.UPDATE_TAG_URL, data)
}

export const reqDeleteTag = (id: number) =>
  request.delete<any, any>(API.DELETE_TAG_URL + id + '/')

export const reqSimilarTags = (keyword: string) => {
  return request.get<any, TagResponseData>(API.TAG_SIMILAR_URL, {
    params: { keyword },
  })
}
